package com.jdllexample.jawin;

import org.jawin.COMException;
import org.jawin.FuncPtr;
import org.jawin.ReturnFlags;
import org.jawin.io.LittleEndianOutputStream;
import org.jawin.io.NakedByteStream;

/**
 * 调用win自带的dll，无需注册。
 * 官方地址：http://sourceforge.net/projects/jawinproject
 * @author cklxh520@gmail.com
 *
 */
public class TestApi {

	public static void main(String[] args) {
		FuncPtr msgBox = null;
		try {
			msgBox = new FuncPtr("USER32.DLL", "MessageBoxW");

			NakedByteStream nbs = new NakedByteStream();
			LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);
			leos.writeInt(0);
			leos.writeStringUnicode("Generic Hello From a DLL");
			leos.writeStringUnicode("From Jawin");
			leos.writeInt(2);
			msgBox.invoke("IGGI:I:", 16, nbs, null, ReturnFlags.CHECK_FALSE);
		} catch (Exception e) {
			// handle exception
			e.printStackTrace();
		} finally {
			if (msgBox != null) {
				try {
					msgBox.close();
				} catch (COMException e) {
					// handle fatal exception
					e.printStackTrace();
				}
			}
		}
	}
}
